import math

WIDTH = 300
HEIGHT = 300

BACK_COLOR = (0, 0, 127)
CIRCLE_COLOR = (0, 200, 0)
sta=[50,50]
end=[200,200]
x, y = 0, 0
spd_x, spd_y = 0, 0
spd=5
r = 20
def on_key_down(key):
    if key == keys.ESCAPE:
        quit()
        
def on_mouse_down(pos):
    print("mouse_down", pos)
    
def on_mouse_up(pos):
    print("mouse_up", pos)

def sp_to_sp(sx,sy,ex,ey):
    global x,y,spd_x,spd_y
    x,y=sx,sy
    spd_x,spd_y=(ex-sx),(ey-sy)

sp_to_sp(sta[0],sta[1],end[0],end[1])

def draw_circle(x, y, r):
    screen.draw.filled_circle((x, y), r, CIRCLE_COLOR)
    return 1

def normalize(x, y):
    s = math.sqrt(x ** 2 + y ** 2)
    return x / s, y / s 

def update():
    global x, y
    global spd_x, spd_y,spd
    if(x>=end[0] or y>=end[1]):
        return
    dx, dy = normalize(spd_x, spd_y)
    spd_val=5
    x += dx * spd_val
    y += dy * spd_val
    if x + r > WIDTH or x - r < 0:
         spd_x *= -1
    if y + r > HEIGHT or y - r < 0:
         spd_y *= -1
        
def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    draw_circle(x, y, r)

